$file = $ARGV[0];
chomp($file);
$file1 = $ARGV[1];
chomp($file1);
open(WRBUFF,">$file1");
open(TBUFF,$file);
#$tline = <TBUFF>;
while($tline = <TBUFF>)
{
        chomp($tline);
	#print $tline."\n";	
        @tp_array = split(/\s/,$tline);
                @array_tped_snps = ();
		$num_tped =0;
                if($tline =~ m/A/)
                {
                        $array_tped_snps[$num_tped] = "A";
                        $num_tped++;
                }
                if($tline =~ m/C/)
                {
                        $array_tped_snps[$num_tped] = "C";
                        $num_tped++;
                }
                if($tline =~ m/G/)
                {
                        $array_tped_snps[$num_tped] = "G";
                        $num_tped++;
                }
                if($tline =~ m/T/)
                {
                        $array_tped_snps[$num_tped] = "T";
                        $num_tped++;
                }
                if($num_tped == 1)
                {
                        $tped_snp1 = $array_tped_snps[0];
                        if($tped_snp1 eq "A")
                        {
                                $tped_snp2 = "-";
          		}
                         if($tped_snp1 eq "T")
                        {
                                $tped_snp2 = "-";
                        }
                         if($tped_snp1 eq "G")
                        {
                                $tped_snp2 = "-";
                        }
                         if($tped_snp1 eq "C")
                        {
                                $tped_snp2 = "-";
                        }

                }
		elsif($num_tped ==0){
				$tped_snp1 = "-";
				$tped_snp2 = "-";
		}
                else
                {
                         $tped_snp1 = $array_tped_snps[0];
                         $tped_snp2 = $array_tped_snps[1];
                }
                #$line1A = "$tp_array[1] $tped_snp1 $tped_snp2";
		#$line2A = 
		#$line = "";
		$mainar[0] = $tp_array[1];
		#print $mainar[0]."\t". $tp_array[1]."\n";
		$mainar[1] = $tped_snp1;
		$mainar[2] = $tped_snp2;
		$A = 3;
		$A1 = 0;
		$A2 =0;
                for($g=4;$g<@tp_array;$g++)
                {
                        $ssnp1 = $tp_array[$g];
                        $g++;
                        $ssnp2 = $tp_array[$g];
                        if($ssnp1 eq $tped_snp1 && $ssnp2  eq $tped_snp1)
                        {
                                #$line =$line." 1 0";
                                #$line =$line." 2";
				$mainar[$A] = "0";
				$A++;		
				$A1++;
                        }
                        elsif($ssnp1 eq $tped_snp2 && $ssnp2  eq $tped_snp2)
                        {
                                #$line =$line." 0 0";
                                #$line =$line." 0";
				$mainar[$A] = "2";
                                $A++;
				$A2++;
                        }
			elsif($ssnp1 eq "0" && $ssnp2  eq "0")
			{
				#$line =$line."  ";
				$mainar[$A] = "-";
                                $A++;
			}
                        else
                        {       #$line =$line." 0 1";
                                #$line =$line." 1";
				$mainar[$A] = "1";
                                $A++;
                        }
		         #print WRBUFF $line."\n";
                }
		#print $A1."\t".$A2."\n";
		
		if($A1 < $A2)
		{
			$mainar[1] = $tped_snp2;
                	$mainar[2] = $tped_snp1;
			$tem1 = shift(@mainar);
			$tem2 = shift(@mainar);
			$tem3 = shift(@mainar);
			$line = join(" ",@mainar);
			$line =~ s/2/3/g;
			$line =~ s/0/2/g;
			$line =~ s/3/0/g;
			$line = $tem1." ".$tem2." ".$tem3." ".$line;
		}
		else
		{
			$line = join(" ",@mainar);
		}
		
                        print WRBUFF $line."\n";
		#	print $line."\n";
                	$numm_count++;
}
                   
